#!/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
#  
#  
# Licensed Materials - Property of IBM 
#  
# (C) COPYRIGHT International Business Machines Corp. 2002,2004 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)04   1.2         src/rsct/cfg_access/refgpfsct.sh, cfg.access, rsct_rzauh, rzauh0431a 6/21/02 21:12:44

PATH=/usr/sbin/rsct/install/bin:/usr/sbin/rsct/bin:/usr/bin:/bin:/usr/sbin:/sbin
export PATH

# If this node appears to already be a member of a GPFS cluster,
# ensure the node is registered with HA services.  Ignore errors.
mmhaFile="/usr/lpp/mmfs/bin/mmha"
mmsdrfsFile="/var/mmfs/gen/mmsdrfs"
mmfsNodeDataFile="/var/mmfs/gen/mmfsNodeData"
if [[ -f $mmsdrfsFile ]] && [[ -f $mmfsNodeDataFile ]] && [[ -f $mmhaFile ]]
then
    nodeData=$(/bin/grep -e ':20_MEMBER_NODE::' $mmfsNodeDataFile)
    sdrfsData=$(/bin/awk -F ":" '
      $2 == "00_VERSION_LINE" { clusterId  = $14 }
      $2 == "810_HATS_HDR"    { cthatsPort = $6  }
      $2 == "820_HAGS_HDR"    { cthagsPort = $6  }
      END { print clusterId":"cthatsPort":"cthagsPort }
    ' $mmsdrfsFile)
    IFS_sv="$IFS"
    IFS=':'
    set -- $sdrfsData
    clusterId=$1
    cthatsPort=$2
    cthagsPort=$3
    set -- $nodeData
    nodeNumber=$5
    IFS="$IFS_sv"
    if [[ -n "$clusterId"  ]] && [[ -n "$nodeNumber" ]] && \
       [[ -n "$cthatsPort" ]] && [[ -n "$cthagsPort" ]]
    then
	/usr/sbin/rsct/bin/cthactrl -i -c $clusterId -n $nodeNumber \
        	 -e gpfs -p "cthats=$cthatsPort,cthags=$cthagsPort"
	exit 0	# if it reinstalls
    fi
fi 

exit 1	# if it does not reinstall
